package com.uenpay.im.weight;

import android.content.Context;
import android.content.DialogInterface;

import com.uenpay.im.R;
import com.uenpay.im.callback.IOnBottomDialogListener;

/**
 * @author SL
 * @created 2016-1-3 上午11:41:59
 * @copyRight http://www.qiyunxin.com
 * @function dialog管理
 */
public class DialogUtility {

	/**
	 * 普通Dialog
	 * 
	 * @param _Context
	 * @param ContentStrResId
	 *            提示内容
	 * @param LeftBtnStrResId
	 *            左按钮文本
	 * @param RightBtnStrResId
	 *            右按钮文本
	 * @param isCancelable
	 *            是否可撤销
	 * @param iOnBottomDialogListener
	 *            回调按钮
	 */
	public static void showDialog(Context _Context, int ContentStrResId,
			int LeftBtnStrResId, int RightBtnStrResId,
			final boolean isCancelable,
			final IOnBottomDialogListener iOnBottomDialogListener) {

		MyDialog.Builder alertDialog = new MyDialog.Builder(_Context);
		alertDialog.setTitle(R.string.dialog_title);
		alertDialog.setMessage(ContentStrResId);
		alertDialog.setPositiveButton(LeftBtnStrResId,
				new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int which) {
						dialog.dismiss();
						iOnBottomDialogListener.onClicked();
					}
				});

		alertDialog.setNegativeButton(RightBtnStrResId,
				new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int which) {
						dialog.dismiss();
					}
				});
		alertDialog.create().show();
		alertDialog.getDialog().setCancelable(isCancelable);
	}

	/**
	 * 普通Dialog
	 * 
	 * @param _Context
	 * @param ContentStrResId
	 *            提示内容
	 * @param LeftBtnStrResId
	 *            左按钮文本
	 * @param RightBtnStrResId
	 *            右按钮文本
	 * @param isCancelable
	 *            是否可撤销
	 * @param iOnBottomDialogListener
	 *            回调按钮
	 */
	public static void showDialog(Context _Context, String ContentStrResId,
			int LeftBtnStrResId, int RightBtnStrResId,
			final boolean isCancelable,
			final IOnBottomDialogListener iOnBottomDialogListener) {

		MyDialog.Builder alertDialog = new MyDialog.Builder(_Context);
		alertDialog.setTitle(R.string.dialog_title);
		alertDialog.setMessage(ContentStrResId);
		alertDialog.setPositiveButton(LeftBtnStrResId,
				new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int which) {
						dialog.dismiss();
						iOnBottomDialogListener.onClicked();
					}
				});

		alertDialog.setNegativeButton(RightBtnStrResId,
				new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int which) {
						dialog.dismiss();
					}
				});
		alertDialog.create().show();
		alertDialog.getDialog().setCancelable(isCancelable);
	}

	/**
	 * 单按钮Dialog
	 * 
	 * @param _Context
	 * @param ContentStrResId
	 * @param btnStrResId
	 * @param iOnBottomDialogListener
	 */
	public static void showSingleBtnDialog(Context _Context,
			int ContentStrResId, int btnStrResId, final boolean isCancelable,
			final IOnBottomDialogListener iOnBottomDialogListener) {

		MyDialogSingleButton.Builder alertDialog = new MyDialogSingleButton.Builder(
				_Context);
		alertDialog.setMessage(ContentStrResId);
		alertDialog.setPositiveButton(btnStrResId,
				new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int which) {
						dialog.dismiss();
						iOnBottomDialogListener.onClicked();
					}
				});
		alertDialog.create().show();
		alertDialog.getDialog().setCancelable(isCancelable);
	}

	/**
	 * 单按钮Dialog
	 * 
	 * @param _Context
	 * @param ContentStrResId
	 * @param btnStrResId
	 * @param iOnBottomDialogListener
	 */
	public static void showSingleBtnDialog(Context _Context,
			String ContentStrResId, int btnStrResId,
			final boolean isCancelable,
			final IOnBottomDialogListener iOnBottomDialogListener) {

		MyDialogSingleButton.Builder alertDialog = new MyDialogSingleButton.Builder(
				_Context);
		alertDialog.setMessage(ContentStrResId);
		alertDialog.setPositiveButton(btnStrResId,
				new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int which) {
						dialog.dismiss();
						iOnBottomDialogListener.onClicked();
					}
				});
		alertDialog.create().show();
		alertDialog.getDialog().setCancelable(isCancelable);
	}
	

	public interface IEditDialogListener {
		public abstract void onClick(String editContent);
	}

	/**
	 * 含输入框的dialog
	 * 
	 * @param _Context
	 * @param isCancelable
	 * @param mIEditDialogListener
	 */
	public static void showEditDialog(Context _Context,
			final boolean isCancelable,
			final IEditDialogListener mIEditDialogListener) {
		MyDialogEditText.Builder builder = new MyDialogEditText.Builder(
				_Context);
		builder.setPositiveButton(new MyDialogEditText.IButtonOnClickListener() {

			@Override
			public void onClick(MyDialogEditText mMyDialogEditText,
					String editContent) {
				mMyDialogEditText.dismiss();
				mIEditDialogListener.onClick(editContent);
			}
		});
		builder.create().show();
		builder.getDialog().setCancelable(isCancelable);
	}

}
